00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef EXPORTSWSHNT33_HPP_
00016 #define EXPORTSWSHNT33_HPP_
00017
00018 #include <iostream>
00019 #include <string>
00020 #include <vector>
00021 #include <map>
00022
00023 #include "gridpack/parallel/communicator.hpp"
00024 #include "gridpack/component/data_collection.hpp"
00025 #include "gridpack/parser/dictionary.hpp"
00026 #include "gridpack/network/base_network.hpp"
00027 #include "gridpack/export/base_export.hpp"
00028
00029 namespace gridpack {
00030 namespace expnet {
00031
00032 template <class _network>
00033 class ExportSwShnt33
00034 {
00035 public:
00036
00037
00038
00039
00040 explicit ExportSwShnt33(boost::shared_ptr<_network> network) :
00041 p_network(network), p_comm(network->communicator())
00042 {
00043 }
00044
00045
00046
00047
00048 virtual ~ExportSwShnt33(){}
00049
00050
00051
00052
00053
00054
00055
00056
00057 void writeSwShntBlock(std::ofstream &fout)
00058 {
00059 BaseExport<_network> exprt(p_comm);
00060 int me = p_comm.rank();
00061
00062 int nbus = p_network->numBuses();
00063 gridpack::component::DataCollection *data;
00064 int i;
00065 char buf[MAX_STRING_SIZE];
00066 std::vector<text_line> text_data;
00067 for (i=0; i<nbus; i++) {
00068 if (p_network->getActiveBus(i)) {
00069 data = p_network->getBusData(i).get();
00070 double rval;
00071 int ival;
00072 std::string sval;
00073 char *ptr = buf;
00074 if (data->getValue(SWSHUNT_BUSNUMBER,&ival)) {
00075 sprintf(ptr,"%d,",ival);
00076 ptr += strlen(ptr);
00077 ival = 1;
00078 data->getValue(SHUNT_MODSW,&ival);
00079 sprintf(ptr,"%d,",ival);
00080 ptr += strlen(ptr);
00081 ival = 0;
00082 data->getValue(SHUNT_ADJM,&ival);
00083 sprintf(ptr,"%d,",ival);
00084 ptr += strlen(ptr);
00085 ival = 1;
00086 data->getValue(SHUNT_SWCH_STAT,&ival);
00087 sprintf(ptr,"%d,",ival);
00088 ptr += strlen(ptr);
00089 rval = 1.0;
00090 data->getValue(SHUNT_VSWHI,&rval);
00091 sprintf(ptr,"%f,",rval);
00092 ptr += strlen(ptr);
00093 rval = 1.0;
00094 data->getValue(SHUNT_VSWLO,&rval);
00095 sprintf(ptr,"%f,",rval);
00096 ptr += strlen(ptr);
00097 ival = 0;
00098 data->getValue(SHUNT_SWREM,&ival);
00099 sprintf(ptr,"%d,",ival);
00100 ptr += strlen(ptr);
00101 rval = 100.0;
00102 data->getValue(SHUNT_RMPCT,&rval);
00103 sprintf(ptr,"%f,",rval);
00104 ptr += strlen(ptr);
00105 sval = "\' \'";
00106 data->getValue(SHUNT_RMIDNT,&sval);
00107 sprintf(ptr,"%s,",sval.c_str());
00108 ptr += strlen(ptr);
00109 rval = 0.0;
00110 data->getValue(SHUNT_BINIT,&rval);
00111 sprintf(ptr,"%f",rval);
00112 ptr += strlen(ptr);
00113 int icnt = 0;
00114 while (icnt<9) {
00115 char ni[32], bi[32];
00116 sprintf(ni,"SHUNT_N%d",icnt+1);
00117 sprintf(bi,"SHUNT_B%d",icnt+1);
00118 if (data->getValue(ni,&ival) && data->getValue(bi,&rval)) {
00119 sprintf(ptr,",%d,%f",ival,rval);
00120 ptr += strlen(ptr);
00121 } else {
00122 break;
00123 }
00124 icnt++;
00125 }
00126 sprintf(ptr,"\n");
00127 text_line text;
00128 strcpy(text.text,buf);
00129 text.global_idx = p_network->getGlobalBusIndex(i);
00130 text.device_idx = 0;
00131 text_data.push_back(text);
00132 }
00133 }
00134 }
00135 if (me == 0) {
00136 fout << "0 / END FACTS DATA, BEGIN SWITCHED SHUNT DATA"
00137 << std::endl;
00138 }
00139 exprt.writeDataBlock(fout, text_data);
00140 if (me == 0) {
00141 fout << "0 / END SWITCHED SHUNT DATA"
00142 << std::endl;
00143 }
00144 }
00145
00146 private:
00147 boost::shared_ptr<_network> p_network;
00148
00149 gridpack::parallel::Communicator p_comm;
00150 };
00151
00152 }
00153 }
00154
00155 #endif